package com.mail.server.service;

import cn.hutool.core.collection.CollUtil;
import com.mail.dubbo.api.UmsResourceCategoryApi;
import com.mail.model.db.UmsResourceCategory;
import com.mail.server.common.R;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @author 吕永乐
 * @date 2022/06/23 11:30
 **/
@Service
public class UmsResourceCategoryService {

    @DubboReference
    private UmsResourceCategoryApi umsResourceCategoryApi;

    /**
     * 查询所有后台资源分类
     *
     * @return
     */
    public List<UmsResourceCategory> listAll() {
        List<UmsResourceCategory> umsResourceCategories = umsResourceCategoryApi.getAll();
        if (CollUtil.isEmpty(umsResourceCategories)) {
            return new ArrayList<>();
        }
        return umsResourceCategories;
    }

    public R create(UmsResourceCategory category) {
        umsResourceCategoryApi.create(category);
        return R.success(null);
    }

    // 根据ID删除后台资源
    public void deleteCategoryById(Long id) {
        umsResourceCategoryApi.deleteCategoryById(id);
    }

    // 修改后台资源分类
    public void updateCategoryById(Long id, UmsResourceCategory resourceCategory) {
        umsResourceCategoryApi.updateCategoryById(id,resourceCategory);
    }
}
